'''
Created on 10 dec 2011

@author: Adam
'''
import clr
from sunray.cmd import Cmd

clr.AddReference('Microsoft.Xna.Framework')
clr.AddReference('Microsoft.Xna.Framework.Game') 

from Microsoft.Xna.Framework import DrawableGameComponent, GameComponent

class CharacterManager(DrawableGameComponent):
    '''
    This class handels everything about npcs and the player.
    '''
    def __init__(self, game):
        '''
        Constructor
        '''
        self._game = game
        self._characters = []
    
    def AddCharacter(self, character):
        self._characters.append(character)
        
    def Update(self, gametime):
        for c in self._characters:
            c.update(gametime)
    
    def Draw(self, gametime):
        for c in self._characters:
            c.draw(self._game.SpriteBatch)


class ScriptManager(GameComponent):
    '''
    The Sunray Engines main class for scripting and is a game component.
    '''

    def __init__(self, game):
        '''
        Constructor
        '''
      
        self._cmd = Cmd()
        
        def get_scripts(self, val):
            return self._cmd.scripts.Keys
        
        self.Scripts = property(fget = get_scripts)
    
    def Update(self, gametime):
        GameComponent.Update(self, gametime)
        
    def Read(self, line=None):
        if not line:
            self._cmd.read(raw_input('>>> '))
        else:
            self._cmd.read(line)
            
    def LoopRead(self):
        self.__printIntro()
        while self._cmd.read(raw_input('>>> ')):
            pass
        
    def AddScript(self, name, func):
        self._cmd.scripts[name] = func
        
    def __printIntro(self):
        print "Welcome to the Sunray Engine Cmd."
        print "basic commands are: [<<<]             [cmds]"
        print "                 [End Cmd] [Get a list of available cmds]" 